var uid = 0;
export default class Dep {
    constructor() {
        console.log("我是Dep");
        this.id = uid++;
        //用数组存储订阅者,存放wacher实例
        this.subs = [];
    };
    /**
     * 添加订阅
     * @param {*} sub 
     */
    addSub(sub) {
        this.subs.push(sub)
    };
    /**
     * 通知更新
     */
    notify() {
        console.log("我是notify");
        //浅克隆
        const subs = this.subs.slice();

        for (let i = 0; i < subs.length; i++) {
            subs[i].update();
        }
    };
    /**
     * 添加依赖
     */
    depend() {
        //Dep.target为全局变量
        if (Dep.target) {
            this.addSub(Dep.target);
        }
    };
}